package it.antonio.ilpizze.reflection;

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ConstructorAccessor {
	private Constructor<?> constr;

	public ConstructorAccessor(Constructor<?> constr) {
		super();
		this.constr = constr;
	}
	
	public Annotation[] getAnnotations() {
		return constr.getAnnotations();
	}

	public Class<?>[] getParameterTypes() {
		return constr.getParameterTypes();
	}
	

	public Annotation[][] getParameterAnnotations() {
		return constr.getParameterAnnotations();
	}

	public boolean isAccessible() {
		return constr.isAccessible();
	}
	
	public boolean isAnnotationPresent(Class<? extends Annotation> arg0) {
		return constr.isAnnotationPresent(arg0);
	}

	public Object newInstance(Object... args){
        try {
                return constr.newInstance(args);
        } catch (IllegalArgumentException e) {
                throw new ReflectionException(e.getMessage(),e);
        } catch (IllegalAccessException e) {
                throw new ReflectionException(e.getMessage(),e);
        } catch (InvocationTargetException e) {
                throw new ReflectionException(e.getMessage(),e);
        } catch (InstantiationException e) {
        	throw new ReflectionException(e.getMessage(),e);
        }
	}
}
